﻿using System;
using EPiServer.Filters;
using EPiServer.Core;

namespace EPiBoost.Core.Filters.PageFilters
{  
    public class FilterExcludeCurrentPage : IPageFilter
    {
          
        public FilterExcludeCurrentPage()
        {
        }
       
        public void Filter(PageDataCollection pages)
        {
            var currentPage = Helpers.HttpContextHelper.GetCurrentPageFromHttpContext();
            if(currentPage==null){ return; }

            for (int i = pages.Count - 1; i >= 0; i--)
            {      
                if (currentPage.PageLink == pages[i].PageLink)
                {
                    pages.RemoveAt(i);
                }                 
            }
        }

        public void Filter(object sender, FilterEventArgs e)
        {
            this.Filter(e.Pages);
        }

        public bool ShouldFilter(PageData page)
        {
            throw new NotImplementedException();
        }
    }
}